part of flutter_project_tool;

void updateConstants({
  required String universalLinkHost,
  required String appName,
  required String appId,
  required String urlScheme,
  required String qqAppId,
  required String qqAppKey,
  required String wxAppId,
  required String wxSecret,
  required String umengKey,
  required String version,
  required String jpushKey,
  required String platform,
  required String useProtocol,
  required String privacyProtocol,
  String? appKey,
}) {
  final file = File(_kConstantsPath);
  var stringValue = file
      .readAsStringSync()
      .replaceFirst(RegExp(r'kAppName[\s\S]*?;'), 'kAppName = \'$appName\';')
      .replaceFirst(RegExp(r'kAppId[\s\S]*?;'), 'kAppId = \'$appId\';')
      .replaceFirst(
          RegExp(r'kUrlScheme[\s\S]*?;'), 'kUrlScheme = \'$urlScheme\';')
      .replaceFirst(RegExp(r'kQQAppId[\s\S]*?;'), 'kQQAppId = \'$qqAppId\';')
      .replaceFirst(RegExp(r'kQQAppKey[\s\S]*?;'), 'kQQAppKey = \'$qqAppKey\';')
      .replaceFirst(RegExp(r'kQQUniversalLink[\s\S]*?;'),
          'kQQUniversalLink = \'https://$universalLinkHost/qq_conn/$qqAppId/\';')
      .replaceFirst(RegExp(r'kWxAppId[\s\S]*?;'), 'kWxAppId = \'$wxAppId\';')
      .replaceFirst(RegExp(r'kWxSecret[\s\S]*?;'), 'kWxSecret = \'$wxSecret\';')
      .replaceFirst(RegExp(r'kWxUniversalLink[\s\S]*?;'),
          'kWxUniversalLink = \'https://$universalLinkHost/$urlScheme/\';')
      .replaceFirst(RegExp(r'kUmengKey[\s\S]*?;'), 'kUmengKey = \'$umengKey\';')
      .replaceFirst(RegExp(r'kVersion[\s\S]*?;'), 'kVersion = \'$version\';')
      .replaceFirst(RegExp(r'kJPushKey[\s\S]*?;'), 'kJPushKey = \'$jpushKey\';')
      .replaceFirst(RegExp(r'kPlatform[\s\S]*?;'), 'kPlatform = \'$platform\';')
      .replaceFirst(RegExp(r'kUseProtocol[\s\S]*?;'),
          'kUseProtocol = kWebBaseUrl + \'$useProtocol\';')
      .replaceFirst(RegExp(r'kPrivacyProtocol[\s\S]*?;'),
          'kPrivacyProtocol = kWebBaseUrl + \'$privacyProtocol\';');
  if (appKey != null) {
    stringValue = stringValue.replaceFirst(
        RegExp(r'kAppKey[\s\S]*?;'), 'kAppKey = \'$appKey\';');
  }
  file.writeAsStringSync(stringValue);
  print('更新constants完成');
}
